//
//  Controller-model.swift
//  jocool
//
//  Created by tong on 16/6/20.
//  Copyright © 2016年 zhuxietong. All rights reserved.
//

import UIKit
import JoLoading



public protocol MoRequestTask {
    func mo_request_send()
    func mo_request_alert(msg:String,title:String,bt_title:String)
    func mo_request_load(obj:Any)
    func mo_handle(status:ResponseStatus,message:String)
    func mo_tip_login()

}

extension MoRequestTask where Self: UIViewController
{
    public func mo_request_send()
    {
    }
    
    public func mo_handle(status:ResponseStatus,message:String)
    {
        switch status {
        case .unAuth:
            mo_tip_login()
        case .success:
            if self is LoadingPresenter{
                
                
            }

        default:
            break
        }
    }

    
    public func mo_request_load(obj:Any){
        
    }

    public func mo_tip_login(){
        self.mo_request_alert(msg: "请登录后查看相关内容".loc, title: "提示".loc, bt_title: "立即登录".loc)
    }
    

    
    
    public func mo_request_alert
        (
        msg:String = "请检查网络链接是否正常".loc,
        title:String = "数据链接失败".loc,
        bt_title:String = "重试".loc
        )
    {
        if let p_self : LoadingPresenter = self as? LoadingPresenter
        {
            weak var wself = self
            if bt_title.len < 1
            {
                p_self.loadingV.show(message: msg, title: title)
                return
            }
            p_self.loadingV.handle(message: msg, title: title, button: bt_title, handAction: {
                 wself?.mo_request_send()
            })
           
//            guard let loading = p_self.loadingV as? JoLoading else{return}
//            p_self.loadingV.handle(message: msg, title: title, button: bt_title, handAction: { () -> Void in
//                wself?.mo_request_send()
//            })
        }
    }


}

